<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="my" uri="myTag/core"%>
<!DOCTYPE html>
<html>
	<head>
		<title>统计分析列表</title>
		<%@include file="/script/myJs/common.jspf"%>
		<script type="text/javascript" src="script/chart/echarts/echarts.min.js"></script>
	</head>
	<body>
		<div class="easyui-layout" data-options="fit:true">
			<!-- 左侧调查分类菜单 -->
			<div data-options="region:'west',border:false" style="width: 240px;padding:5px">
				<div class="easyui-panel" data-options="fit:true">
					<ul id="surveyTypeTree"></ul>
					<div id="surveyTypeTreeMenu" class="easyui-menu" style="width:120px;">
						<div class="menu-sep"></div>
						<div onclick="surveyTypeTreeFlush()" data-options="iconCls:'icon-reload'">刷新</div>
					</div>
				</div>
			</div>
			<div data-options="region:'center',border:false">
				<%-- 统计分析查询条件 --%>
				<div id="statisAnlsToolbar" style="padding:0 30px;">
					<div class="conditions">
						<form id="statisAnlsQueryForm">
							<input type="hidden" id="statisAnls_one" name="one">
							<span class="con-span">名称：</span>
							<input name="two" class="easyui-textbox" style="width:166px;height:35px;line-height:35px;">
							<span class="con-span">问卷：</span>
							<input name="three" class="easyui-textbox" style="width:166px;height:35px;line-height:35px;">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" data-options="selected:true" onclick="statisAnlsQuery();">查询</a>
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-clear" onclick="statisAnlsReset();">重置</a>
						</form>
					</div>
					<div class="opt-buttons">
						<my:auth url="statisAnls/toStatisAnls"><a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" data-options="selected:true" onclick="toStatisAnls();">统计分析</a></my:auth>
					</div>
				</div>
				<%-- 统计分析数据表格 --%>
				<table id="statisAnlsGrid">
				</table>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		//定义变量
		var statisAnlsGrid = $("#statisAnlsGrid"); //统计分析表格对象
		var statisAnlsQueryForm = $("#statisAnlsQueryForm"); //统计分析查询对象
		var surveyTypeTree = $("#surveyTypeTree"); //调查分类树对象
		var curSelSurveyTypeId = ""; //当前选中的调查分类ID
		var curSelSurveyTypeName = ""; //当前选中的调查分类名称
	
		//页面加载完毕，执行如下方法：
		$(function() {
			initStatisAnlsGrid();
			initSurveyTypeTree();
		});
	
		//初始化统计分析表格
		function initStatisAnlsGrid() {
			statisAnlsGrid.datagrid( {
				url : "",
				onDblClickRow : <my:auth url="statisAnls/toStatisAnls">toStatisAnlsForDblClick</my:auth>,
				toolbar : "#statisAnlsToolbar",
				columns : [[ 
						{field : "ID", title : "", checkbox : true}, 
						{field : "NAME", title : "名称", width : 80, align : "center"},
						{field : "PAPER_NAME", title : "问卷", width : 80, align : "center"},
						{field : "START_TIME_STR", title : "开始时间", width : 80, align : "center"},
						{field : "END_TIME_STR", title : "结束时间", width : 80, align : "center"},
						{field : "STATE_NAME", title : "状态", width : 80, align : "center"}
						]]
			});
		}
		
		//初始化调查分类树
		function initSurveyTypeTree(){
			surveyTypeTree.tree({
				idFiled : "ID",
				textFiled : "NAME",
				parentField : "PARENT_ID",
				iconClsFiled : "ICON",
				checkedFiled : "CHECKED",
				lines : true,
			    url : "statisAnls/surveyTypeTreeList",
				dnd : true,
				onContextMenu : function(e, node){
					e.preventDefault();
					$(this).tree("select", node.target);
					$("#surveyTypeTreeMenu").menu("show", {
						left : e.pageX,
						top : e.pageY
					})
				},
				onSelect : function(node){
					curSelSurveyTypeId = node.ID;
					curSelSurveyTypeName = node.NAME;
					
					$("#statisAnls_one").val(curSelSurveyTypeId);
					statisAnlsGrid.datagrid("uncheckAll");
					statisAnlsGrid.datagrid("reload", $.fn.my.serializeObj(statisAnlsQueryForm));
				},
				onLoadSuccess : function(node, data){
					if(!curSelSurveyTypeId || !statisAnlsGrid.datagrid("options").url){//如果是第一次
						curSelSurveyTypeId = 1;
						statisAnlsGrid.datagrid("options").url = "statisAnls/list";
					}
					
					var node = surveyTypeTree.tree("find", curSelSurveyTypeId);
					if(!node){
						curSelSurveyTypeId = 1;
						node = surveyTypeTree.tree("find", curSelSurveyTypeId);
					}
					surveyTypeTree.tree("select", node.target);
				}
			});
		}
	
		//统计分析查询
		function statisAnlsQuery() {
			statisAnlsGrid.datagrid("uncheckAll");
			statisAnlsGrid.datagrid("load", $.fn.my.serializeObj(statisAnlsQueryForm));
		}
	
		//统计分析重置
		function statisAnlsReset() {
			statisAnlsQueryForm.form("reset");
			statisAnlsQuery();
		}
		
		//到达统计分析页面
		function toStatisAnls() {
			var statisAnlsGridRows = statisAnlsGrid.datagrid("getChecked");
			if (statisAnlsGridRows.length != 1) {
				parent.$.messager.alert("提示消息", "请选择一行数据！", "info");
				return;
			}
			
			var statisAnlsCfgDialog;
			var params = {surveyId : statisAnlsGridRows[0].ID };
			statisAnlsCfgDialog = $("<div/>").dialog({
				href : "statisAnls/toStatisAnls",
				queryParams : params,
				title : "统计分析",
				maximized : true,
				buttons : [{
					text : "关闭", 
					iconCls : "icon-ok",
					selected : true, 
					handler : function (){
						statisAnlsCfgDialog.dialog("close");
					}
				}]
			});
		}
		
		//到达统计分析页面
		function toStatisAnlsForDblClick(rowIndex, rowData) {
			statisAnlsGrid.datagrid("uncheckAll");
			statisAnlsGrid.datagrid("checkRow", rowIndex);
			toStatisAnls();
		}
	</script>
</html>